//第25天

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"math/rand"
	"time"
)

//随机生成6位数
func test1() string {
	str := "0123456789"
	arr := []byte(str)
	arrLen := len(str)
	nums := []byte{}
	rand.Seed(time.Now().UnixNano())
	for i:=0; i<6; i++ {
		nums = append(nums, arr[rand.Intn(arrLen)])
	}
	fmt.Println(string(nums))
	return string(nums)
}

type MyInt int

func (i *MyInt)test2(){
	fmt.Println(*i)
}

type People interface {
	Speak(string) string
}

type Student struct {
	Name string
	Age int
}

func (stu *Student) Speak(str string) (res string){
	if str == "speak" {
		fmt.Println("speak")
		res = str
	}
	res = "talk"
	return
}
//格式化输出
func (stu *Student) String() string {
	b, err := json.Marshal(*stu)
	if err != nil {
		return fmt.Sprintf("%+v", *stu)
	}
	var out bytes.Buffer
	err = json.Indent(&out, b, "", "    ")
	if err != nil {
		return fmt.Sprintf("%+v", *stu)
	}
	return out.String()
}


func main() {
	fmt.Println("沧浪之水")

	test1()
	i := MyInt(10)
	i.test2()

	var people People = &Student{"ddd", 222}
	people.Speak("speak")
	fmt.Println(people)

	s := "22222222222"
	fmt.Printf("%c[1;32m%s%c[0m\n", 0x1B, s, 0x1B)
}